{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"https://colab.research.google.com/github/jeffheaton/t81_558_deep_learning/blob/master/manual_setup.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# T81-558: Applications of Deep Neural Networks\n",
    "**Manual Python Setup**\n",
    "* Instructor: [Jeff Heaton](https://sites.wustl.edu/jeffheaton/), McKelvey School of Engineering, [Washington University in St. Louis](https://engineering.wustl.edu/Programs/Pages/default.aspx)\n",
    "* For more information visit the [class website](https://sites.wustl.edu/jeffheaton/t81-558/)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Software Installation\n",
    "This class is technically oriented.  A successful student needs to be able to compile and execute Python code that makes use of TensorFlow for deep learning. There are two options for you to accomplish this:\n",
    "\n",
    "* Install Python, TensorFlow and some IDE (Jupyter, TensorFlow, and others)\n",
    "* Use Google CoLab in the cloud\n",
    "\n",
    "## Installing Python and TensorFlow\n",
    "\n",
    "These instructions apply primarily to Linux, Windows or Intel Mac. If you have a newer Mac with Apple Silicone (M1/M2/M3/etc) please refer to [this guide](tensorflow-install-conda-mac-metal-jul-2022.ipynb). It is possible to install and run Python/TensorFlow entirely from your computer, without the need for Google CoLab. Running TensorFlow locally does require some software configuration and installation.  If you are not confortable with software installation, just use Google CoLab.  These instructions show you how to install TensorFlow for both CPU and GPU. Many of the examples in this class will achieve considerable performance improvement from a GPU.\n",
    "\n",
    "The first step is to install Python 3.9.  As of August 2022, this is the latest version of Python 3.  I recommend using the Miniconda (Anaconda) release of Python, as it already includes many of the data science related packages that are needed by this class.  Anaconda directly supports Windows, Mac, and Linux.  Miniconda is the minimal set of features from the extensive Anaconda Python distribution.  Download Miniconda from the following URL:\n",
    "\n",
    "* [Miniconda](https://docs.conda.io/en/latest/miniconda.html)\n",
    "\n",
    "Once you install Miniconda, we will install Jupyter, which is the editor you will use in this course.\n",
    "\n",
    "```\n",
    "conda install -y jupyter\n",
    "```\n",
    "\n",
    "We will actually launch Jupyter later.\n",
    "\n",
    "You must make sure that TensorFlow has the version of Python that it is compatible with.  The best way to accomplish this is with an Anaconda environment.  Each environment that you create can have its own Python version, drivers, and Python libraries.  I suggest that you create an environment to hold the Python instance for this class.  Use the following command to create your environment. I am calling the environment **tensorflow**, you can name yours whatever you like.\n",
    "\n",
    "```\n",
    "conda create --name tensorflow python=3.9\n",
    "```\n",
    "\n",
    "To enter this environment, you must use the following command: \n",
    "\n",
    "```\n",
    "conda activate tensorflow\n",
    "```\n",
    "\n",
    "For now, lets add Jupyter support to your new environment.\n",
    "\n",
    "```\n",
    "conda install -c conda-forge nb_conda\n",
    "```\n",
    "\n",
    "The examples in this course has been tested on all of these versions.  The next two sections describe how to install TensorFlow for either a CPU or GPU. To use GPU, you must have a [compatible NVIDIA GPU](https://developer.nvidia.com/cuda-gpus).\n",
    "\n",
    "\n",
    "## Install TensorFlow for CPU Only\n",
    "The following command installs TensorFlow for CPU support.  Even if you have a GPU, it will not be used.\n",
    "\n",
    "```\n",
    "conda install -c anaconda tensorflow\n",
    "```\n",
    "\n",
    "\n",
    "## Install TensorFlow for GPU and CPU\n",
    "\n",
    "The following command installs TensorFlow for GPU support.  All of the complex driver installations should be handled by this command.\n",
    "\n",
    "```\n",
    "conda install -c anaconda tensorflow-gpu\n",
    "```\n",
    "\n",
    "## Install Additional Libraries for ML\n",
    "\n",
    "There are several additional libraries that you will need for this course.  This command will install them.  Make sure you are still in your **tensorflow** environment.\n",
    "\n",
    "```\n",
    "conda env update --file tools.yml\n",
    "```\n",
    "\n",
    "The [tools.yml](https://raw.githubusercontent.com/jeffheaton/t81_558_deep_learning/master/tools.yml) file is located in the root directory for this GitHub repository.\n",
    "\n",
    "## Register your Environment\n",
    "\n",
    "The following command registers your **tensorflow** environment. Again, make sure you \"conda activate\" your new **tensorflow** environment.\n",
    "\n",
    "```\n",
    "python -m ipykernel install --user --name tensorflow --display-name \"Python 3.8 (tensorflow)\"\n",
    "```\n",
    "\n",
    "## Testing your Environment\n",
    "\n",
    "You can now start Jupyter notebook.  Use the following command.\n",
    "\n",
    "```\n",
    "jupyter notebook\n",
    "```\n",
    "\n",
    "You can now run the following code to check that you have the versions expected."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tensor Flow Version: 2.1.0\n",
      "Keras Version: 2.2.4-tf\n",
      "\n",
      "Python 3.7.7 (default, May  6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)]\n",
      "Pandas 1.0.5\n",
      "Scikit-Learn 0.23.1\n",
      "GPU is available\n"
     ]
    }
   ],
   "source": [
    "# What version of Python do you have?\n",
    "import sys\n",
    "\n",
    "import tensorflow.keras\n",
    "import pandas as pd\n",
    "import sklearn as sk\n",
    "import tensorflow as tf\n",
    "\n",
    "print(f\"Tensor Flow Version: {tf.__version__}\")\n",
    "print(f\"Keras Version: {tensorflow.keras.__version__}\")\n",
    "print()\n",
    "print(f\"Python {sys.version}\")\n",
    "print(f\"Pandas {pd.__version__}\")\n",
    "print(f\"Scikit-Learn {sk.__version__}\")\n",
    "gpu = len(tf.config.list_physical_devices('GPU'))>0\n",
    "print(\"GPU is\", \"available\" if gpu else \"NOT AVAILABLE\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
